﻿var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

var phone = sessionStorage.getItem("userPhone");
$(function () {
    //初始化加载月包
    if (isiOS) {
        $("#linkSMS").attr("href", "sms:10086&body=XDJSY");
        $("#linkSMS1").attr("href", "sms:10086&body=XDJSY");
    }
    else {
        $("#linkSMS").attr("href", "sms:10086?body=XDJSY");
        $("#linkSMS1").attr("href", "sms:10086?body=XDJSY");
    }

    $("#feePhone").text(phone);

    choose();
    //choose_submit();
    // tiyan();
    prompt();
    frame_choose();
    frame_submit();
    cancel();
    $(".try select").change(function () {
        var options = $(".try select option:selected");
        $.post("/Home/GetShopListMethod", { 'cityId': options.val(), 'pageType': 2 }, GetYearShopMethodResponse);
    })

    $(".volume-frame .close-img").click(function () {
        $(".volume-frame").hide();
    });
    $.post("/Home/PageClick", { 'phone': phone, 'pageType': 2 });
});
function choose() {
    $(".order-menu li").click(function () {
        $(".order-menu li").removeClass("choosed").addClass("choose");
        $(this).addClass("choosed");
        var type = $(this).attr("data-type");  //类型
        SelectType("linkSMS", type);
    })
}
function tiyan() {
    //$(".lists-btn img").click(function () {
    $(".tiyan-frame").show();
    //如果未订购
    $(".prompt-frame").show();
    $(".frame-order").hide();
    ////如果已订购
    //$(".prompt-frame").hide();
    //$(".frame-order").show();
    $("body,html").css({
        "overflow": "hidden"
    })
    //});
}
function prompt() {
    $(".prompt-frame .tijiao").click(function () {
        $(".prompt-frame").hide();
        $(".frame-order").show();
    })
}
function frame_choose() {
    $(".frame-order-menu li").click(function () {
        $(".frame-order-menu li").removeClass("choosed").addClass("choose");
        $(this).addClass("choosed");
        var type = $(this).attr("data-type");  //类型
        SelectType("linkSMS1", type);
    })
}
function frame_submit() {
    $(".frame-choose-btn").click(function () {
        $(".tiyan-frame").hide();
        $("body,html").css({
            "overflow": "auto"
        });
        //这里做提交
    })
}
function cancel() {
    $(".tiyan-frame .close-img").click(function () {
        $(".tiyan-frame").hide();
        $("body,html").css({
            "overflow": "auto"
        })
    })
}


var shopName = "";
var ticketName = "";  
function RecTicket(shopId, sName, tName) {

    var isRec = $("#ticketShopId").val();
    if (isRec > 0)
        return layer.msg("每人限领一张！");
    shopName = sName;
    ticketName = tName;
    $.post("/Home/RecYearTicket", { 'phone': phone, 'shopId': shopId }, GetRecYearTicketResponse);
}


function GetRecYearTicketResponse(data) {
    if (data.Success) {
        window.location.href = "/Home/RecTicketSuccess?name=" + shopName + "&ticketName="+ticketName;
    } else {
        if (data.Code == 3) {
            return tiyan();
        }
        layer.msg(data.Message);
    }
}



function GetYearShopMethodResponse(data) {
    if (data.Success) {
        var r = data.Message;
        $(".chengdu img").attr("src", "../image/city/" + data.CityId + ".png")
        var str = "";
        var shop = $("#ticketShopId").val();
        if (r.length > 0) {
            for (var i = 0; i < r.length; i++) {
                var strshop = "";
                if (r[i].CityName.length > 1)
                    strshop = "(" + r[i].CityName + ")";
                str += '<div class="lists"><div class="lists-content" onclick="ShopDetails(' + r[i].ShopId + ',2)">';
                str += '<img src="../image/shoptype/shop_' + r[i].ShopType + '.png" alt=""><div class="lists-logo">';
                str += '<img src="http://fuwu.xdjsclub.com/Shops/images/' + r[i].ImgLogo + '/logo.jpg" alt=""><p>' + r[i].ShopName + strshop + '</p><p>' + r[i].TicketName + '</p></div></div>';
                str += '<div class="lists-btn">';
                if (shop == r[i].ShopId) {
                    str += '<img src="../image/current/btn-lingqu2.png"  alt="已领取按钮" />  ';
                } else {
                    str += '<img src="../image/free/btn-lingqu.png" onclick="RecTicket(' + r[i].ShopId + ',\'' + r[i].ShopName + '\',\'' + r[i].TicketName + '\')" alt="领取按钮">';
                }
                str += '</div></div>';
            }
        }
        $(".menu").html(str);

    } else {
        layer.msg("系统繁忙，请稍后再试！");
    }
}
